﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Huirui.Cavan.Core.Persistent;
using Huirui.Cavan.Domain.MainBoundedContext.SearchModule;
using Huirui.Cavan.Core.MyLinq;
using Huirui.Cavan.Core.Extension;

namespace Huirui.Cavan.Domain.MainBoundedContext.SystemModule
{
    public class CurrencySpecification : ISpecification<Currency, CurrencySearch>
    {
        #region ISpecification<Currency,CurrencySearch> Members

        public CurrencySearch SearchParams
        {
            get;
            set;
        }

        #endregion

        #region ISpecification<Currency> Members

        public System.Linq.Expressions.Expression<Func<Currency, bool>> Expression
        {
            get 
            {
                IQueryBuilder<Currency> queryBuilder = QueryBuilder.Create<Currency>();

                if (null != SearchParams)
                {
                    if (SearchParams.CorporationCode.IsNotEmpty())
                    {
                        queryBuilder = queryBuilder.Equals(c => c.Corporation.Id, SearchParams.CorporationCode);
                    }
                    if (SearchParams.Code.IsNotEmpty())
                    {
                        queryBuilder = queryBuilder.Equals(c => c.Code, SearchParams.Code);
                    }
                    if (SearchParams.IsLocal.HasValue)
                    {
                        queryBuilder = queryBuilder.Equals(c => c.IsLocal, SearchParams.IsLocal.Value);
                    }
                }

                return queryBuilder.Expression.Expand();
            }
        }

        #endregion
    }
}
